package com.ruge.user.controller;

import com.ruge.core.enums.IntegralEnum;
import com.ruge.core.response.Response;
import com.ruge.user.service.IntegralLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author ruge.wu
 * @since 2022/2/11 11:34
 */
@Slf4j
@RestController
@Api(tags = "【用户 积分 相关接口】", value = "【用户 积分 相关接口】")
@RequestMapping("integral")
public class IntegralLogController {

    @Resource
    private IntegralLogService integralLogService;

    @PostMapping("initRule")
    @ApiOperation(value = "【积分】  积分规则初始化")
    public Response initRule() {
        return integralLogService.initRule();
    }


    @GetMapping("getTop")
    @ApiOperation(value = "【积分】  获取积分排行榜前x名")
    public Response getTop(@Valid
                           @ApiParam(value = "前x名") @RequestParam("top") Integer top) {
        return integralLogService.getTop(top);
    }

    @GetMapping("getTopFromRedis")
    @ApiOperation(value = "【积分】  获取积分排行榜前x名")
    public Response getTopFromRedis(@Valid
                                    @ApiParam(value = "前x名") @RequestParam("top") Integer top) {
        return integralLogService.getTopFromRedis(top);
    }

    @GetMapping("getRankByAid")
    @ApiOperation(value = "【积分】  获取指定用户排名")
    public Response getRankByAid(@Valid
                                 @ApiParam(value = "用户id") @RequestParam("aid") Long aid) {
        return integralLogService.getRankByAid(aid);
    }

    @GetMapping("getRankByAidFromRedis")
    @ApiOperation(value = "【积分】  获取指定用户排名")
    public Response getRankByAidFromRedis(@Valid
                                          @ApiParam(value = "用户id") @RequestParam("aid") Long aid) {
        return integralLogService.getRankByAidFromRedis(aid);
    }

    @PostMapping("save")
    @ApiOperation(value = "【积分】  积分操作")
    public Response save(@Valid @ApiParam(value = "用户id") @RequestParam("aid") Long aid,
                         @ApiParam(value = "积分类型") @RequestParam("integralEnum") IntegralEnum integralEnum) {

        return integralLogService.save(aid, integralEnum);
    }
}
